package com.xnyzc.lhy.resource.controller.worksheet;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.resource.entity.worksheet.OaSysWorksheetEntity;
import com.xnyzc.lhy.resource.entity.worksheet.UpdateTicketStatusEntity;
import com.xnyzc.lhy.resource.entity.worksheet.UrgentTicketEntity;
import com.xnyzc.lhy.resource.entity.worksheet.param.heli.LoginSynchronousParam;
import com.xnyzc.lhy.resource.entity.worksheet.param.heli.RoleSynchronousParam;
import com.xnyzc.lhy.resource.service.worksheet.WorkSheetToHeLiService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 调用合力工单 前端控制器
 * </p>
 *
 * @author cuichaoqun
 * @since 2019-11-14
 */
@Slf4j
@RestController
@RequestMapping("/worksheet/toheli")
public class WorkSheetToHeLiController {

    @Autowired
    WorkSheetToHeLiService workSheetToHeLiService;

    /**
     *
     * 调用合力
     *  创建工单接口
     *  第三方来源的工单推送到合力系统，需要传递渠道标识
     *
     * */
    @ApiOperation(value = "创建工单接口", notes = "创建工单接口")
    @PostMapping(value = "/createTicket")
    public Rv createTicket(@RequestBody OaSysWorksheetEntity oaSysWorksheetEntity) {
        return workSheetToHeLiService.createTicket(oaSysWorksheetEntity);
    }

    /**
     *  第三方系统创建的工单如果有加急操作需要实时同步到合力系统
     *
     * */
    @ApiOperation(value = "工单加急接口", notes = "工单加急接口")
    @PostMapping(value = "/urgentTicket")
    public Rv urgentTicket(@RequestBody UrgentTicketEntity urgentTicket) {
        return workSheetToHeLiService.urgentTicket(urgentTicket);
    }

    /**
     *  第三方系统推送过来的工单如果有状态改变操作需要实时同步到合力系统
     *
     * */
    @ApiOperation(value = "工单状态同步接口", notes = "工单状态同步接口")
    @PostMapping(value = "/updateTicketStatus")
    public Rv updateTicketStatus(@RequestBody UpdateTicketStatusEntity ticketStatusEntity) {
        return workSheetToHeLiService.updateTicketStatus(ticketStatusEntity);
    }


    /**
     * 登陆账号同步接口
     *
     * @return
     */
    @ApiOperation(value = "登陆账号同步接口", notes = "登陆账号同步接口")
    @PostMapping(value = "/getLoginSynchronous")
    public Rv getLoginSynchronous(@RequestBody LoginSynchronousParam loginSynchronousParam
    ) {
        try {
            return workSheetToHeLiService.getLoginSynchronous(loginSynchronousParam);
        }catch (Exception ex){
            return Rv.error(EErrorCode.unkown);
        }
    }

    /**
     * 客服角色同步接口。
     *
     * @return
     */
    @ApiOperation(value = "客服角色同步接口", notes = "客服角色同步接口")
    @PostMapping(value = "/getRoleSynchronous")
    public Rv getRoleSynchronous(@RequestBody RoleSynchronousParam roleSynchronousParam
    ) {
        try {
            return workSheetToHeLiService.getRoleSynchronous(roleSynchronousParam);
        }catch (Exception ex){
            return Rv.error(EErrorCode.unkown);
        }
    }
}
